{template 'common/header'}

{if $_GPC['step'] == 1 || $_GPC['step'] == ''}
<div class="account-list-add" id="js-account-post-step1" ng-controller="XzappPostStepOne" ng-cloak>
	<ol class="breadcrumb we7-breadcrumb">
		<a href="{php echo url('account/manage', array('account_type' => ACCOUNT_TYPE_XZAPP_NORMAL))}"><i class="wi wi-back-circle"></i></a>
		<li><a href="{php echo url('account/manage', array('account_type' => ACCOUNT_TYPE_XZAPP_NORMAL))}">熊掌号列表</a></li>
		<li>新建熊掌号</li>
	</ol>
	<div class="panel we7-panel">
		{if !$_W['isfounder']}
		<div class="alert alert-warning hidden">
			温馨提示：
			<i class="fa fa-info-circle"></i>
			Hi，<span class="text-strong">{$_W['username']}</span>，您所在的会员组： <span class="text-strong">{$account_info['group_name']}</span>，
			账号有效期限：<span class="text-strong">{php echo date('Y-m-d', $_W['user']['starttime'])} ~~ {if empty($_W['user']['endtime'])}无限制{else}{php echo date('Y-m-d', $_W['user']['endtime'])}{/if}</span>，
			可创建 <span class="text-strong">{$account_info['maxxzapp']} </span>个熊掌号，已创建<span class="text-strong"> {$account_info['xzapp_num']} </span>个，还可创建 <span class="text-strong">{$account_info['xzapp_limit']} </span>个熊掌号。
		</div>
		{/if}
		<div class="panel-body we7-padding">
			<div class="col-lg-6">
				<div class="title">
					<span class="img img-pen"></span>
					<a href="javascript:;">手动添加熊掌号</a>
				</div>
				<div class="con">
					手动绑定需同步熊掌号接口，在熊掌号后台，基本设置可以获取ClientId和ClientSecret，绑定成功后，将获取的服务器配置接口绑定到熊掌号后台（切记：绑定过程中，一定要注意保持接口参数一致）
				</div>
				<div>
					<a href="{php echo url('xzapp/post-step', array('step' => 2))}" class="btn btn-primary">手动添加熊掌号</a>
				</div>
			</div>
			<div class="col-lg-6">
				<div class="title">
					<span class="img img-tel"></span>
					授权添加熊掌号
				</div>
				<div class="con">
					熊掌号开发者平台-第三方平台开发 <a href="https://xiongzhang.baidu.com/open/thirdparty" class="color-default">熊掌号开发者平台</a>
				</div>
				<div>
					<a href="{$authurl}" class="btn btn-primary">授权添加熊掌号</a>
				</div>
			</div>
		</div>
	</div>
</div>
<script type="text/javascript">
	angular.module('xzApp').value('config', {});
	angular.bootstrap($('#js-account-post-step1'),['xzApp']);
</script>

{elseif $_GPC['step'] == 2}

<div class="account-list-add-step">
	<ol class="breadcrumb we7-breadcrumb">
		<a href="{php echo url('account/manage', array('account_type' => ACCOUNT_TYPE_XZAPP_NORMAL))}"><i class="wi wi-back-circle"></i> </a>
		<li><a href="{php echo url('account/manage', array('account_type' => ACCOUNT_TYPE_XZAPP_NORMAL))}}">熊掌号列表</a></li>
		<li>新建熊掌号</li>
	</ol>
	<div class="we7-step">
		<ul>
			<li class="active">1 设置熊掌号信息</li>
			{if !empty($_W['isfounder'])}
			<li>2 设置权限</li>
			<li>3 引导页面</li>
			{else}
			<li>2 引导页面</li>
			{/if}
		</ul>
	</div>
	<form action="" method="post" class="we7-form" enctype="multipart/form-data" id="js-account-post-step2" ng-controller="XzappPostStepTwo" ng-cloak>
		<input type="hidden" name="step" value="2">
		<!--第二步:基本信息-->
		<div class="form-group">
			<label for="" class="control-label col-sm-2">熊掌号名称</label>
			<div class="form-controls col-sm-8">
				<input type="text" name="cname" class="form-control" ng-model="account.name" autocomplete="off" />
				<span class="help-block">填写熊掌号的账号名称</span>
			</div>
		</div>
		<div class="form-group">
			<label for="" class="control-label col-sm-2">描述（签名）</label>
			<div class="form-controls col-sm-8">
				<textarea style="height: 80px;" class="form-control" name="description" ng-bind="account.description"></textarea>
				<span class="help-block"></span>
			</div>
		</div>
		<div class="form-group">
			<label for="" class="control-label col-sm-2">熊掌号ID</label>
			<div class="form-controls col-sm-8">
				<input type="text" name="original" class="form-control" ng-model="account.original" autocomplete="off" />
				<span class="help-block">熊掌号ID不能修改,请谨慎填写</span>
			</div>
		</div>
		<div class="form-group">
			<label for="" class="control-label col-sm-2">类型</label>
			<div class="form-controls col-sm-8">
				<select name="level" class="we7-select">
					<option value="1" ng-selected="account.level == 1">个人</option>
					<option value="2" ng-selected="account.level == 2">媒体</option>
					<option value="3" ng-selected="account.level == 3">企业</option>
					<option value="4" ng-selected="account.level == 4">政府</option>
					<option value="4" ng-selected="account.level == 5">其他组织</option>
				</select>
			</div>
		</div>
		<div class="form-group">
			<label for="" class="control-label col-sm-2">ClientId</label>
			<div class="form-controls col-sm-8">
				<input type="text" name="key" class="form-control" ng-model="account.key" autocomplete="off"/>
				<span class="help-block">请填写熊掌号后台的ClientId</span>
			</div>
		</div>
		<div class="form-group">
			<label for="" class="control-label col-sm-2">ClientSecret</label>
			<div class="form-controls col-sm-8">
				<input type="text" name="secret" class="form-control" ng-model="account.secret" autocomplete="off"/>
				<span class="help-block">请填写熊掌号后台的ClientSecret</span>
			</div>
		</div>
		<div class="form-group">
			<label class="control-label col-sm-2">Oauth 2.0</label>
			<div class="form-controls col-sm-8">
				<p class="form-control-static">在熊掌号请求用户网页授权之前，开发者需要先到熊掌号后台的【开发设置】<b>基本设置</b>中配置授权回调域名。{if $_W['isfounder']}{/if}</p>
			</div>
		</div>
		<div class="form-group">
			<label for="" class="control-label col-sm-2">头像</label>
			<div class="form-controls col-sm-8">
				<div class="input-more we7-input-img" ng-class="{'active': account.headimg}">
					<img ng-src="{{account.headimg}}" width="150px" ng-if="account.headimg" ng-style="{'height': 'auto'}">
					<a href="javascript:;" class="input-addon" ng-click="uploadMultiImage('headimg')" ng-hide="account.headimg"><span>+</span></a>
					<input type="text" name="headimg" ng-model="account.headimg" ng-style="{'display' : 'none'}">
					<div class="cover-dark">
						<a href="javascript:;" class="cut" ng-click="uploadMultiImage('headimg')">更换</a>
						<a href="javascript:;" class="del" ng-click="delMultiImage('headimg')"><i class="fa fa-times text-danger"></i></a>
					</div>
				</div>
				<span class="help-block"></span>
			</div>
		</div>

		<div class="form-group">
			<input type="submit" name="submit" class="btn btn-primary btn-submit" value="下一步"/>
			<input type="hidden" name="token" value="{$_W['token']}">
		</div>
	</form>
</div>
<script type="text/javascript">
	angular.module('xzApp').value('config', {

	});
	angular.bootstrap($('#js-account-post-step2'),['xzApp']);
</script>

{elseif $_GPC['step'] == 3}

<div class="account-list-add-step">
	<ol class="breadcrumb we7-breadcrumb">
		<a href="{php echo url('account/manage', array('account_type' => ACCOUNT_TYPE_XZAPP_NORMAL))}"><i class="wi wi-back-circle"></i> </a>
		<li><a href="{php echo url('account/manage', array('account_type' => ACCOUNT_TYPE_XZAPP_NORMAL))}">熊掌号列表</a></li>
		<li>新建熊掌号</li>
	</ol>
	<div class="we7-step">
		<ul>
			<li>1 设置熊掌号信息</li>
			{if !empty($_W['isfounder'])}
			<li class="active">2 设置权限</li>
			<li>3 引导页面</li>
			{else}
			<li class="active">2 引导页面</li>
			{/if}
		</ul>
	</div>
	<form action="" method="post" class="we7-form" id="js-account-post-step3" ng-controller="XzappPostStepThree" ng-cloak>
		<input type="hidden" name="step" value="3">
		<input type="hidden" name="uniacid" value="{$_GPC['uniacid']}">
		<input type="hidden" name="acid" value="{$_GPC['acid']}">
		<!--第三步:设置权限-->
		<div class="form-group">
			<label for="" class="control-label col-sm-2">熊掌号过期时间</label>
			<div class="form-controls col-sm-8">
				<div class="form-group">
					<input id="istop-1" type="radio" name="is-set-endtime" ng-model="owner.endtime" value="1">
					<label for="istop-1">设置</label>
					<input id="istop-2" type="radio" name="is-set-endtime" ng-model="owner.endtime" value="0" ng-checked="1">
					<label for="istop-2">不限</label>
				</div>
				<div class="form-group" ng-show="owner.endtime == 1">
					{php echo tpl_form_field_date('endtime', $owner['endtime']);}
					<span class="help-block">用户的使用时间过期时，将来无法登录，熊掌号权限也暂停使用，不设置为永久可用</span>
				</div>
			</div>
		</div>
		<div class="panel we7-panel">
			<div class="panel-heading">主管理员设置</div>
			<div class="panel-body we7-padding-top">
				<div class="form-group">
					<label for="" class="control-label col-sm-2">主管理员</label>
					<div class="form-controls col-sm-8">
						<div class="input-group">
							<input type="hidden" name="uid" value="{$owner['uid']}" id="manager">
							<input type="text" class="form-control" value="{$owner['username']}" id="showname">
							<span class="input-group-btn">
									<button class="btn btn-default" ng-click="selectOwner($event)">选择管理员</button>
								</span>
						</div>
						<span class="help-block">如果是新用户,请先 <a href="{url 'user/create'}" target="_blank" class="color-default">添加用户</a></span>
					</div>
				</div>
				<div class="form-group">
					<label for="" class="control-label col-sm-2">修改管理员用户权限组</label>
					<div class="form-controls col-sm-8">
						<select name="groupid" class="we7-select col-sm-3" id="groupid" ng-model="owner.groupid" ng-change="changeGroup()">
							<option value="0">不设置</option>
							{loop $groups $row}
							{php $package = $row['package'] ? implode(',', iunserializer($row['package'])) : '';}
							<option value="{$row['id']}" {if $row['id'] == $owner['groupid']}selected{/if} data-package="[{$package}]">{$row['name']}</option>
							{/loop}
						</select>
					</div>
				</div>
			</div>
		</div>
		<table class="table we7-table table-hover">
			<tr>
				<td colspan="2" class="text-left bg-light-gray">熊掌号可使用应用权限组（各权限组均包含系统模块和微站默认模板）</td>
			</tr>
			<tr>
				<th class="text-left bg-light-gray">应用权限组</th>
				<th class="text-right bg-light-gray">操作</th>
			</tr>
			{if permission_check_account_user('see_account_manage_module_tpl_all_permission')}
			<tr>
				<td class="text-left">
					<input id="check-0" type="checkbox" name="package[]" autocomplete="off" value="-1" {if is_array($owner['group']['package']) && in_array('-1', $owner['group']['package'])}checked disabled{/if}{if is_array($extend['package']) && !empty($extend['package'][-1])}checked {/if} />
					<label for="check-0" class="we7-padding-left we7-margin-horizontal-none">所有服务</label>
				</td>
				<td>
					<div class="link-group">
						<a href="javascript:void(0);" class="js-unfold" data-toggle="collapse" data-target="#extend0" ng-click="changeText($event)">展开</a>
					</div>
				</td>
			</tr>
			<tr class="collapse bg-light-gray" aria-expanded="true" id="extend0">
				<td colspan="2">
					<div class="col-sm-1 color-gray text-left we7-padding-none">应用权限</div>
					<div class="col-sm-11">
						<div class="col-sm-3 text-left">
							<span class="label label-danger">系统所有模块</span>
						</div>
					</div>
					<div class="col-sm-1 color-gray text-left we7-padding-none">模板权限</div>
					<div class="col-sm-11">
						<div class="col-sm-3 text-left">
							<span class="label label-danger">系统所有模板</span>
						</div>
					</div>
				</td>
			</tr>
			{/if}
			{loop $unigroups $package}
			<tr>
				<td class="text-left">
					<input id="check-{$package['id']}" type="checkbox" name="package[]" autocomplete="off" {if is_array($owner['group']['package']) && in_array($package['id'], $owner['group']['package'])}checked disabled{/if} {if is_array($extend['package']) && !empty($extend['package'][$package['id']])}checked {/if} value="{$package['id']}" />
					<label for="check-{$package['id']}" class="we7-padding-left we7-margin-horizontal-none">{$package['name']}</label>
				</td>
				<td class="text-left">
					<div class="link-group">
						<a href="javascript:void(0);" class="color-default js-unfold" data-toggle="collapse" data-target="#extend{$package['id']}" ng-click="changeText($event)">展开</a>
					</div>
				</td>
			</tr>
			<tr class="collapse bg-light-gray" aria-expanded="true" id="extend{$package['id']}">
				<td colspan="2">
					<div>
						<div class="col-sm-1 color-gray text-left we7-padding-none">应用权限</div>
						<div class="col-sm-11">
							{if !empty($package['modules'])}
							{loop $package['modules'] $module}
							<div class="col-sm-3 text-left">
								<img src="{$module['logo']}" style="width:50px;height:50px;">
								<a href="javascript:void(0);">{$module['title']}</a>
							</div>
							{/loop}
							{else}
							<div class="col-sm-3 text-left">---</div>
							{/if}
						</div>
					</div>
					<div>
						<div class="col-sm-1 color-gray text-left we7-padding-none">模板权限</div>
						<div class="col-sm-11">
							{if !empty($package['templates']) && $package['templates'] != 'N;'}
							{loop $package['templates'] $template}
							<div class="col-sm-3 text-left">
								<i class="glyphicon glyphicon-th-large"></i>
								<a href="javascript:void(0);">{$template['title']}</a>
							</div>
							{/loop}
							{else}
							<div class="col-sm-3 text-left">
								<a href="">---</a>
							</div>
							{/if}
						</div>
					</div>
				</td>
			</tr>
			{/loop}
			<tr class="account-package-extra" {if empty($owner['extend'])}style="display:none;"{/if}>
			<td class="text-left bg-light-gray" colspan="2">添加其他应用权限</td>
			</tr>
			<tr class="account-package-extra" {if empty($owner['extend'])}style="display:none;"{/if}>
			<td class="text-left">
				应用权限：
				<span class="js-extra-modules">
							{loop $owner['extend']['modules'] $module}
							<span class="label label-info">{$module['title']}</span>
							<input type="hidden" value="{$module['name']}" name="extra[modules][]">
							{/loop}
						</span>
			</td>
			<td class="text-left">
				模板权限：
				<span class="js-extra-templates">
							{loop $owner['extend']['templates'] $template}
							<span class="label label-info">{$template['title']}</span>
							<input type="hidden" value="{$template['id']}" name="extra[templates][]">
							{/loop}
						</span>
			</td>
			</tr>
			<tr>
				<td class="text-center" colspan="2">
					<span class="btn btn-primary" data-toggle="modal" data-target="#jurisdiction-add">添加权限</span>
				</td>
			</tr>
		</table>
		<div class="form-group">
			<input type="submit" name="submit" value="下一步" class="btn btn-primary btn-submit"/>
			<input type="hidden" name="token" value="{$_W['token']}">
		</div>
		<div class="modal" id="jurisdiction-add">
			<div class="modal-dialog we7-modal-dialog">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
						<ul role="tablist" class="nav nav-pills">
							<li class="active"><a class="we7-padding-horizontal" data-toggle="tab" role="tab" aria-controls="content-modules" href="#content-modules">模块</a></li>
							<li><a class="we7-padding-horizontal" data-toggle="tab" role="tab" aria-controls="content-templates" href="#content-templates">模板</a></li>
						</ul>
					</div>
					<div class="modal-body">
						<div class="tab-content">
							<div id="content-modules" class="tab-pane active" role="tabpanel">
								<table class="table we7-table table-hover vertical-middle">
									<col width="280px">
									<col width="220px">
									<col />
									<tr>
										<th>模块名称</th>
										<th>模块标识</th>
										<th></th>
									</tr>
									{loop $modules $module}
									<tr>
										<td>{$module['title']}{if $module['issystem']}<span class="label label-success">系统模块</span>{/if}</td>
										<td>{$module['name']}</td>
										<td><a class="btn btn-default js-btn-select {if is_array($extend['modules']) && in_array($module['name'], $extend['modules'])}btn-primary{/if}" data-title="{$module['title']}" data-name="{$module['name']}" onclick="$(this).toggleClass('btn-primary')">选取</a></td>
									</tr>
									{/loop}
								</table>
							</div>
							<div id="content-templates" class="tab-pane" role="tabpanel">
								<table class="table we7-table table-hover vertical-middle">
									<col width="280px">
									<col width="220px">
									<col />
									<tr>
										<th>模板名称</th>
										<th>模板标识</th>
										<th></th>
									</tr>
									{loop $templates $temp}
									<tr>
										<td>{$temp['title']}</td>
										<td>{$temp['name']}</td>
										<td><a class="btn btn-default js-btn-select {if is_array($extend['templates']) && in_array($temp['id'], $extend['templates'])}btn-primary{/if}" data-title="{$temp['title']}" data-name="{$temp['id']}" onclick="$(this).toggleClass('btn-primary')">选取</a></td>
									</tr>
									{/loop}
								</table>
							</div>
						</div>
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-primary" ng-click="addPermission()">确定</button>
						<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
					</div>
				</div>
			</div>
		</div>
	</form>
</div>
<script type="text/javascript">
	angular.module('xzApp').value('config', {
		notify: {php echo !empty($notify) ? json_encode($notify) : 'null'},
		owner: {php echo !empty($owner) ? json_encode($owner) : 'null'},
		links: {
			userinfo: "{php echo url('xzapp/post-step', array('step' => 3, 'get_type' => 'userinfo'))}",
		}
	});

	angular.bootstrap($('#js-account-post-step3'),['xzApp']);
</script>

{elseif $_GPC['step'] == 4}

<div class="account-list-add-step">
	<ol class="breadcrumb we7-breadcrumb">
		<a href="{php echo url('account/manage', array('account_type' => ACCOUNT_TYPE_XZAPP_NORMAL))}"><i class="wi wi-back-circle"></i> </a>
		<li><a href="{php echo url('account/manage', array('account_type' => ACCOUNT_TYPE_XZAPP_NORMAL))}">熊掌号列表</a></li>
		<li>新建熊掌号</li>
	</ol>
	<div class="we7-step">
		<ul>
			<li>1 设置熊掌号信息</li>
			{if !empty($_W['isfounder'])}
			<li>2 设置权限</li>
			<li class="active">3 引导页面</li>
			{else}
			<li class="active">2 引导页面</li>
			{/if}
		</ul>
	</div>
	<div class="we7-form" id="js-account-post-step4" ng-controller="XzappPostStepFour" ng-cloak>
		<!--第四步:引导页面-->
		<p class="alert alert-info">您绑定的熊掌号：<strong ng-bind="account.name"></strong>，请按照下列引导完成配置。</p>
		<div class="panel we7-panel" ng-if="account.isconnect == 0">
			<div class="panel-heading">
				第一步
			</div>
			<div class="panel-body">
				<div class="alert">
					<i class="wi wi-info-sign"></i>
					<span>登录 <a href="https://xiongzhang.baidu.com" class="color-default" target="_blank">熊掌号后台</a>，点击左侧菜单开发-开发设置，进入 [ <em class=" color-red">基本设置</em> ]</span>
				</div>
				<div class="form-group">
					<div class="img"><img src="./resource/images/xz-guide-01.png"></div>
				</div>
			</div>
		</div>
		<div class="panel we7-panel" ng-if="account.isconnect == 0">
			<div class="panel-heading">
				第二步
			</div>
			<div class="panel-body">
				<div class="alert">
					<i class="wi wi-info-sign"></i>
					<span>开发设置-基本设置中，找到［<em class="color-red"> 服务器配置</em> ］栏目下URL和Token设置</span>
				</div>
				<div class="form-group">
					<div class="img"><img src="./resource/images/xz-guide-02.png"/></div>
					<p># 将以下链接链接填入对应输入框：</p>
					<div class="form-group clip">
						<label class="col-sm-1 control-label">URL:</label>
						<div class="col-sm-11 input-group">
							<p class="form-control-static">
								<a href="javascript:;">{$_W['siteroot']}api.php?id={$account['acid']}</a>
								<a href="javascript:;" id="copy-0" class="color-default" clipboard supported="supported" text="url" on-copied="success('0')">&nbsp;&nbsp;点击复制</a>
							</p>
						</div>
					</div>
					<div class="form-group clip">
						<label class="col-sm-1 control-label">Token:</label>
						<div class="col-sm-11 input-group">
							<p class="form-control-static">
								<a href="javascript:;" ng-bind="account.token"></a>
								<a href="javascript:;" id="copy-1" class="color-default" clipboard supported="supported" text="account.token" on-copied="success('1')">&nbsp;&nbsp;点击复制</a>
							</p>
						</div>
					</div>
					<div class="form-group clip">
						<label class="col-sm-2 control-label">EncodingAESKey:</label>
						<div class="col-sm-10 input-group">
							<p class="form-control-static">
								<a href="javascript:;" title="点击复制EncodingAESKey" ng-bind="account.encodingaeskey"></a>
								<a href="javascript:;" id="copy-2" class="color-default" clipboard supported="supported" text="account.encodingaeskey" on-copied="success('2')">&nbsp;&nbsp;点击复制</a>
							</p>
						</div>
					</div>
					<p># 如果以前已填写过URL和Token，请点击[<em class=" color-red"> 修改配置 </em>] ，再填写上述链接</p>
				</div>
			</div>
		</div>
		<div class="panel we7-panel">
			<div class="panel-heading">
				第三步
			</div>
			<div class="panel-body">
				<div class="alert">
					<i class="wi wi-info-sign"></i>
					<span class="color-red" ng-if="account.isconnect == 1">熊掌号 <span ng-bind="account.name"></span> 接入成功</span>
					<span class="color-red" ng-if="account.isconnect == 0">熊掌号 <span ng-bind="account.name"></span> 正在等待接入……请及时按照以上步骤操作接入熊掌号</span>
				</div>
				<div class="form-group">
					<div ng-if="account.isconnect == 0">
						<p># 检查熊掌号配置</p>
						<p># 编辑熊掌号 <a ng-href="{{links.post}}acid={{account.acid}}&uniacid={{account.uniacid}}">{$account['name']}</a></p>
						<a href="javascript:window.location.reload();" class="btn btn-success">检测是否接入成功</a>&nbsp;
						<a ng-href="{{links.switch}}uniacid={{account.uniacid}}" class="btn btn-primary">暂不接入，先去查看熊掌号功能</a>&nbsp;
						<a ng-href="{{links.manage}}&account_type={{account.type}}" class="btn btn-info">返回熊掌号列表</a>
					</div>
					<div ng-if="account.isconnect == 1">
						<a ng-href="{{links.post}}acid={{account.acid}}&uniacid={{account.uniacid}}&account_type={{account.type}}" class="btn btn-primary">管理熊掌号</a>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<script type="text/javascript">
	angular.module('xzApp').value('config', {
		account: {php echo !empty($account) ? json_encode($account) : 'null'},
		links: {
			siteroot: "{$_W['siteroot']}",
			post: "{php echo url('account/post')}",
			manage: "{php echo url('account/manage')}",
			switch: "{php echo url('account/display/switch')}",
		}
	});
	angular.bootstrap($('#js-account-post-step4'),['xzApp']);
</script>

{/if}

{template 'common/footer'}
